package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.EmployeeDAO;
import cn.edu.scau.cmi.hombio.dao.MedicineTakeDAO;
import cn.edu.scau.cmi.hombio.dao.MedicineTakeDetailDAO;
import cn.edu.scau.cmi.hombio.dao.TaskDAO;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.MedicineTake;
import cn.edu.scau.cmi.hombio.domain.MedicineTakeDetail;
import cn.edu.scau.cmi.hombio.domain.Task;

import cn.edu.scau.cmi.hombio.service.MedicineTakeService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for MedicineTake entities
 * 
 */

@Controller("MedicineTakeRestController")

public class MedicineTakeRestController {

	/**
	 * DAO injected by Spring that manages Employee entities
	 * 
	 */
	@Autowired
	private EmployeeDAO employeeDAO;

	/**
	 * DAO injected by Spring that manages MedicineTake entities
	 * 
	 */
	@Autowired
	private MedicineTakeDAO medicineTakeDAO;

	/**
	 * DAO injected by Spring that manages MedicineTakeDetail entities
	 * 
	 */
	@Autowired
	private MedicineTakeDetailDAO medicineTakeDetailDAO;

	/**
	 * DAO injected by Spring that manages Task entities
	 * 
	 */
	@Autowired
	private TaskDAO taskDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for MedicineTake entities
	 * 
	 */
	@Autowired
	private MedicineTakeService medicineTakeService;

	/**
	 * Delete an existing Employee entity
	 * 
	 */
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByPharmacistId/{employee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteMedicineTakeEmployeeByPharmacistId(@PathVariable Integer medicinetake_id, @PathVariable Integer related_employeebypharmacistid_id) {
		medicineTakeService.deleteMedicineTakeEmployeeByPharmacistId(medicinetake_id, related_employeebypharmacistid_id);
	}

	/**
	* Delete an existing MedicineTakeDetail entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/medicineTakeDetails/{medicinetakedetail_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteMedicineTakeMedicineTakeDetails(@PathVariable Integer medicinetake_id, @PathVariable Integer related_medicinetakedetails_id) {
		medicineTakeService.deleteMedicineTakeMedicineTakeDetails(medicinetake_id, related_medicinetakedetails_id);
	}

	/**
	* Get Task entity by MedicineTake
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/task", method = RequestMethod.GET)
	@ResponseBody
	public Task getMedicineTakeTask(@PathVariable Integer medicinetake_id) {
		return medicineTakeDAO.findMedicineTakeByPrimaryKey(medicinetake_id).getTask();
	}

	/**
	* Save an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByPharmacistId", method = RequestMethod.PUT)
	@ResponseBody
	public Employee saveMedicineTakeEmployeeByPharmacistId(@PathVariable Integer medicinetake_id, @RequestBody Employee employeebypharmacistid) {
		medicineTakeService.saveMedicineTakeEmployeeByPharmacistId(medicinetake_id, employeebypharmacistid);
		return employeeDAO.findEmployeeByPrimaryKey(employeebypharmacistid.getId());
	}

	/**
	* Delete an existing Task entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/task/{task_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteMedicineTakeTask(@PathVariable Integer medicinetake_id, @PathVariable Integer related_task_id) {
		medicineTakeService.deleteMedicineTakeTask(medicinetake_id, related_task_id);
	}

	/**
	* Show all MedicineTake entities
	* 
	*/
	@RequestMapping(value = "/MedicineTake", method = RequestMethod.GET)
	@ResponseBody
	public List<MedicineTake> listMedicineTakes() {
		return new java.util.ArrayList<MedicineTake>(medicineTakeService.loadMedicineTakes());
	}

	/**
	* Delete an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByTakerId/{employee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteMedicineTakeEmployeeByTakerId(@PathVariable Integer medicinetake_id, @PathVariable Integer related_employeebytakerid_id) {
		medicineTakeService.deleteMedicineTakeEmployeeByTakerId(medicinetake_id, related_employeebytakerid_id);
	}

	/**
	* View an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByTakerId/{employee_id}", method = RequestMethod.GET)
	@ResponseBody
	public Employee loadMedicineTakeEmployeeByTakerId(@PathVariable Integer medicinetake_id, @PathVariable Integer related_employeebytakerid_id) {
		Employee employee = employeeDAO.findEmployeeByPrimaryKey(related_employeebytakerid_id, -1, -1);

		return employee;
	}

	/**
	* Create a new MedicineTake entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake", method = RequestMethod.POST)
	@ResponseBody
	public MedicineTake newMedicineTake(@RequestBody MedicineTake medicinetake) {
		medicineTakeService.saveMedicineTake(medicinetake);
		return medicineTakeDAO.findMedicineTakeByPrimaryKey(medicinetake.getId());
	}

	/**
	* Save an existing Task entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/task", method = RequestMethod.PUT)
	@ResponseBody
	public Task saveMedicineTakeTask(@PathVariable Integer medicinetake_id, @RequestBody Task task) {
		medicineTakeService.saveMedicineTakeTask(medicinetake_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Select an existing MedicineTake entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}", method = RequestMethod.GET)
	@ResponseBody
	public MedicineTake loadMedicineTake(@PathVariable Integer medicinetake_id) {
		return medicineTakeDAO.findMedicineTakeByPrimaryKey(medicinetake_id);
	}

	/**
	* Delete an existing MedicineTake entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteMedicineTake(@PathVariable Integer medicinetake_id) {
		MedicineTake medicinetake = medicineTakeDAO.findMedicineTakeByPrimaryKey(medicinetake_id);
		medicineTakeService.deleteMedicineTake(medicinetake);
	}

	/**
	* Create a new Employee entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByTakerId", method = RequestMethod.POST)
	@ResponseBody
	public Employee newMedicineTakeEmployeeByTakerId(@PathVariable Integer medicinetake_id, @RequestBody Employee employee) {
		medicineTakeService.saveMedicineTakeEmployeeByTakerId(medicinetake_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Create a new MedicineTakeDetail entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/medicineTakeDetails", method = RequestMethod.POST)
	@ResponseBody
	public MedicineTakeDetail newMedicineTakeMedicineTakeDetails(@PathVariable Integer medicinetake_id, @RequestBody MedicineTakeDetail medicinetakedetail) {
		medicineTakeService.saveMedicineTakeMedicineTakeDetails(medicinetake_id, medicinetakedetail);
		return medicineTakeDetailDAO.findMedicineTakeDetailByPrimaryKey(medicinetakedetail.getId());
	}

	/**
	* Get Employee entity by MedicineTake
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByTakerId", method = RequestMethod.GET)
	@ResponseBody
	public Employee getMedicineTakeEmployeeByTakerId(@PathVariable Integer medicinetake_id) {
		return medicineTakeDAO.findMedicineTakeByPrimaryKey(medicinetake_id).getEmployeeByTakerId();
	}

	/**
	* Save an existing MedicineTakeDetail entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/medicineTakeDetails", method = RequestMethod.PUT)
	@ResponseBody
	public MedicineTakeDetail saveMedicineTakeMedicineTakeDetails(@PathVariable Integer medicinetake_id, @RequestBody MedicineTakeDetail medicinetakedetails) {
		medicineTakeService.saveMedicineTakeMedicineTakeDetails(medicinetake_id, medicinetakedetails);
		return medicineTakeDetailDAO.findMedicineTakeDetailByPrimaryKey(medicinetakedetails.getId());
	}

	/**
	* View an existing Task entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/task/{task_id}", method = RequestMethod.GET)
	@ResponseBody
	public Task loadMedicineTakeTask(@PathVariable Integer medicinetake_id, @PathVariable Integer related_task_id) {
		Task task = taskDAO.findTaskByPrimaryKey(related_task_id, -1, -1);

		return task;
	}

	/**
	* Save an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByTakerId", method = RequestMethod.PUT)
	@ResponseBody
	public Employee saveMedicineTakeEmployeeByTakerId(@PathVariable Integer medicinetake_id, @RequestBody Employee employeebytakerid) {
		medicineTakeService.saveMedicineTakeEmployeeByTakerId(medicinetake_id, employeebytakerid);
		return employeeDAO.findEmployeeByPrimaryKey(employeebytakerid.getId());
	}

	/**
	* Get Employee entity by MedicineTake
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByPharmacistId", method = RequestMethod.GET)
	@ResponseBody
	public Employee getMedicineTakeEmployeeByPharmacistId(@PathVariable Integer medicinetake_id) {
		return medicineTakeDAO.findMedicineTakeByPrimaryKey(medicinetake_id).getEmployeeByPharmacistId();
	}

	/**
	* Show all MedicineTakeDetail entities by MedicineTake
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/medicineTakeDetails", method = RequestMethod.GET)
	@ResponseBody
	public List<MedicineTakeDetail> getMedicineTakeMedicineTakeDetails(@PathVariable Integer medicinetake_id) {
		return new java.util.ArrayList<MedicineTakeDetail>(medicineTakeDAO.findMedicineTakeByPrimaryKey(medicinetake_id).getMedicineTakeDetails());
	}

	/**
	* View an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByPharmacistId/{employee_id}", method = RequestMethod.GET)
	@ResponseBody
	public Employee loadMedicineTakeEmployeeByPharmacistId(@PathVariable Integer medicinetake_id, @PathVariable Integer related_employeebypharmacistid_id) {
		Employee employee = employeeDAO.findEmployeeByPrimaryKey(related_employeebypharmacistid_id, -1, -1);

		return employee;
	}

	/**
	* Create a new Employee entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/employeeByPharmacistId", method = RequestMethod.POST)
	@ResponseBody
	public Employee newMedicineTakeEmployeeByPharmacistId(@PathVariable Integer medicinetake_id, @RequestBody Employee employee) {
		medicineTakeService.saveMedicineTakeEmployeeByPharmacistId(medicinetake_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Create a new Task entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/task", method = RequestMethod.POST)
	@ResponseBody
	public Task newMedicineTakeTask(@PathVariable Integer medicinetake_id, @RequestBody Task task) {
		medicineTakeService.saveMedicineTakeTask(medicinetake_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Save an existing MedicineTake entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake", method = RequestMethod.PUT)
	@ResponseBody
	public MedicineTake saveMedicineTake(@RequestBody MedicineTake medicinetake) {
		medicineTakeService.saveMedicineTake(medicinetake);
		return medicineTakeDAO.findMedicineTakeByPrimaryKey(medicinetake.getId());
	}

	/**
	* View an existing MedicineTakeDetail entity
	* 
	*/
	@RequestMapping(value = "/MedicineTake/{medicinetake_id}/medicineTakeDetails/{medicinetakedetail_id}", method = RequestMethod.GET)
	@ResponseBody
	public MedicineTakeDetail loadMedicineTakeMedicineTakeDetails(@PathVariable Integer medicinetake_id, @PathVariable Integer related_medicinetakedetails_id) {
		MedicineTakeDetail medicinetakedetail = medicineTakeDetailDAO.findMedicineTakeDetailByPrimaryKey(related_medicinetakedetails_id, -1, -1);

		return medicinetakedetail;
	}
}